package com.digitalchina.lxnsy.api;

import android.app.Activity;
import android.os.Handler;

import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.constant.URL;
import com.digitalchina.lxnsy.toolkit.OkHttpUtil;
import com.digitalchina.lxnsy.xml.RongCloudXML;
import com.digitalchina.lxnsy.xml.UserXML;
import com.lzy.okhttputils.model.HttpParams;
import com.ta.utdid2.android.utils.StringUtils;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：活动接口
 * 包名：com.digitalchina.bigdata.api
 * 创建人：郑皓
 * 创建时间：2018/7/13 10:03
 * 修改备注：
 * ================================================
 */
public class BusinessActivity {

    /**
     * 活动类型-发布
     *
     * @param activity
     * @param handler
     */
    public static void getActivityType(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("pCode","ACTIVITY");
        OkHttpUtil.get(activity, URL.URL_SHARE_FARM_TYPE, "", params, handler, MSG.MSG_GET_ACTIVITY_TYPE_SUCCESS, MSG.MSG_GET_ACTIVITY_TYPE_FIELD);

    }

    /**
     * 活动类型-列表
     *
     * @param activity
     * @param handler
     */
    public static void getActivityTypeList(Activity activity, Handler handler) {

        HttpParams params = new HttpParams();

        OkHttpUtil.post(activity, URL.URL_GET_ACTIVITY_TYPE_LIST, "", params, handler, MSG.MSG_GET_ACTIVITY_TYPE_SUCCESS, MSG.MSG_GET_ACTIVITY_TYPE_FIELD);

    }

    /**
     * 活动详情
     *
     * @param activity
     * @param activityId 活动ID
     * @param handler
     */
    public static void showActivity(Activity activity, String activityId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("activityId", activityId);

        OkHttpUtil.getA(activity, URL.URL_SHOW_ACTIVITY+activityId, "", params, handler, MSG.MSG_SHOW_ACTIVITY_SUCCESS, MSG.MSG_SHOW_ACTIVITY_FIELD);

    }


    /**
     * 修改、发布活动
     *
     * @param activityName      活动名称
     * @param code              活动类型code
     * @param isRegister        活动是否需要报名 0 不需要 1 需要
     * @param registerStartTime 活动报名开始时间
     * @param registerDeadline  活动报名截止时间
     * @param startTime         活动开始时间
     * @param endTime           活动截止时间
     * @param provinceName      省名称
     * @param cityName          市名称
     * @param countyName        区县名称
     * @param address           详细地址
     * @param isFee             是否收费 0:免费 1 收费
     * @param fee               费用价格
     * @param isLimit           是否限制人数 0 不限 1 限制
     * @param num               活动人数
     * @param activityIntroduce 活动介绍
     * @param sponsorName       主办方名称
     * @param sponsorPerson     主办方联系人
     * @param sponsorTel        主办方联系方式
     * @param organizerName     承办方名称
     * @param organizerPerson   承办方联系人
     * @param organizerTel      承办方联系方式
     * @param imgPath           海报
     * @param activityId        有值为修改
     */
    public static void editorActivity(Activity activity, String activityName, String code, String isRegister, String registerStartTime, String registerDeadline, String startTime,
                                      String endTime, String provinceName, String cityName, String countyName, String address, String isFee, String fee, String isLimit, String num,
                                      String activityIntroduce, String sponsorName, String sponsorPerson, String sponsorTel, String organizerName, String organizerPerson,
                                      String organizerTel, String imgPath, String activityId, String subjectActivityDescImageList, Handler handler) {

//        HttpParams params = new HttpParams();
        JSONObject params = new JSONObject();
        try {
            params.put("activityName", activityName);
            params.put("typeCode", code);
            params.put("isRegister", isRegister);
            params.put("registerStartTime", registerStartTime);
            params.put("registerDeadline", registerDeadline);
            params.put("startTime", startTime);
            params.put("endTime", endTime);
            params.put("provinceCode", provinceName);
            params.put("cityCode", cityName);
            params.put("countyCode", countyName);
            params.put("address", address);
            params.put("isFee", isFee);
            params.put("fee", fee);
            params.put("isLimit", isLimit);
            params.put("num", num);
            params.put("activityIntroduce", activityIntroduce);
            params.put("sponsorName", sponsorName);
            params.put("sponsorPerson", sponsorPerson);
            params.put("sponsorTel", sponsorTel);
            params.put("organizerName", organizerName);
            params.put("organizerPerson", organizerPerson);
            params.put("organizerTel", organizerTel);
            params.put("imgPath", imgPath);
            params.put("userId", UserXML.getUserId(activity));
//            params.put("subjectActivityDescImageList", subjectActivityDescImageList);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));
            params.put("loginUserId",UserXML.getUserId(activity));
            OkHttpUtil.post(activity, URL.URL_EDITOR_ACTIVITY_EDIT+activityId, "", params, handler, MSG.MSG_EDITOR_ACTIVITY_SUCCESS, MSG.MSG_EDITOR_ACTIVITY_FIELD);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }





    /**
     * 修改、发布活动
     *
     * @param activityName      活动名称
     * @param code              活动类型code
     * @param isRegister        活动是否需要报名 0 不需要 1 需要
     * @param registerStartTime 活动报名开始时间
     * @param registerDeadline  活动报名截止时间
     * @param startTime         活动开始时间
     * @param endTime           活动截止时间
     * @param provinceName      省名称
     * @param cityName          市名称
     * @param countyName        区县名称
     * @param address           详细地址
     * @param isFee             是否收费 0:免费 1 收费
     * @param fee               费用价格
     * @param isLimit           是否限制人数 0 不限 1 限制
     * @param num               活动人数
     * @param activityIntroduce 活动介绍
     * @param sponsorName       主办方名称
     * @param sponsorPerson     主办方联系人
     * @param sponsorTel        主办方联系方式
     * @param organizerName     承办方名称
     * @param organizerPerson   承办方联系人
     * @param organizerTel      承办方联系方式
     * @param imgPath           海报
     * @param activityId        有值为修改
     */
    public static void saveActivity(Activity activity, String activityName, String code, String isRegister, String registerStartTime, String registerDeadline, String startTime,
                                      String endTime, String provinceName, String cityName, String countyName, String address, String isFee, String fee, String isLimit, String num,
                                      String activityIntroduce, String sponsorName, String sponsorPerson, String sponsorTel, String organizerName, String organizerPerson,
                                      String organizerTel, String imgPath, String activityId, String subjectActivityDescImageList, Handler handler) {

//        HttpParams params = new HttpParams();
        JSONObject params = new JSONObject();
        try {
            params.put("activityName", activityName);
            params.put("typeCode", code);
            params.put("isRegister", isRegister);
            params.put("registerStartTime", registerStartTime);
            params.put("registerDeadline", registerDeadline);
            params.put("startTime", startTime);
            params.put("endTime", endTime);
            params.put("provinceCode", provinceName);
            params.put("cityCode", cityName);
            params.put("countyCode", countyName);
            params.put("address", address);
            params.put("isFee", isFee);
            params.put("fee", fee);
            params.put("isLimit", isLimit);
            params.put("num", num);
            params.put("activityIntroduce", activityIntroduce);
            params.put("sponsorName", sponsorName);
            params.put("sponsorPerson", sponsorPerson);
            params.put("sponsorTel", sponsorTel);
            params.put("organizerName", organizerName);
            params.put("organizerPerson", organizerPerson);
            params.put("organizerTel", organizerTel);
            params.put("imgPath", imgPath);
            params.put("userId", UserXML.getUserId(activity));
//            params.put("subjectActivityDescImageList", subjectActivityDescImageList);
            params.put("tenantCode", StringUtils.isEmpty(RongCloudXML.getTenantCode(activity))?"T000010":RongCloudXML.getTenantCode(activity));
            params.put("subjectInfoId", RongCloudXML.getSubjectInfoId(activity));
            params.put("loginUserId",UserXML.getUserId(activity));
            OkHttpUtil.post(activity, URL.URL_EDITOR_ACTIVITY, "", params, handler, MSG.MSG_EDITOR_ACTIVITY_SUCCESS, MSG.MSG_EDITOR_ACTIVITY_FIELD);

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    /**
    /**
     * 活动列表
     *
     * @param activity
     * @param keyWord       搜索关键字（活动名称，活动介绍，活动类型名称）
     * @param typeCode      活动类型(typeCode为1时查询首页活动)
     * @param activityState 活动状态 （汉字格式：即将开始，正在进行，已结束）
     * @param page
     * @param num
     * @param handler
     */
    public static void searchActivity(Activity activity, String keyWord, String typeCode, String activityState, int page, int num,String queryDataType, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("activityName", keyWord);
        params.put("typeCode", typeCode);
        params.put("activityState", activityState);
        params.put("page", String.valueOf(page));
        params.put("perPage", String.valueOf(num));
        params.put("queryDataType", "1");
        OkHttpUtil.get(activity, URL.URL_SEARCH_ACTIVITY, "", params, handler, MSG.MSG_SEARCH_ACTIVITY_SUCCESS, MSG.MSG_SEARCH_ACTIVITY_FIELD);

    }

    /**
     * 活动报名
     *
     * @param activity
     * @param activityId
     * @param contacts
     * @param tel
     * @param handler
     */
    public static void signActivity(Activity activity, String activityId, String contacts, String tel, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("activityId", activityId);
        params.put("contacts", contacts);
        params.put("tel", tel);

        OkHttpUtil.post(activity, URL.URL_SIGN_ACTIVITY, "", params, handler, MSG.MSG_SIGN_ACTIVITY_SUCCESS, MSG.MSG_SIGN_ACTIVITY_FIELD);

    }



    /**
     * 我发布的活动
     *
     * @param activity
     * @param page
     * @param num
     * @param handler
     */
    public static void getPublishedActivityAll(Activity activity, int page, int num, Handler handler) {

        HttpParams params = new HttpParams();
//        params.put("userId", UserXML.getUserId(activity));
        params.put("page", String.valueOf(page));
        params.put("perPage", String.valueOf(num));
        params.put("queryDataType", "0");
        params.put("createBy", UserXML.getUserId(activity));



        OkHttpUtil.get(activity, URL.URL_GET_PUBLISHED_ACTIVITY, "", params, handler, MSG.MSG_GET_PUBLISHED_ACTIVITY_SUCCESS, MSG.MSG_GET_PUBLISHED_ACTIVITY_FIELD);

    }


    /**
     * 我发布的活动
     *
     * @param activity
     * @param page
     * @param num
     * @param handler
     */
    public static void getPublishedActivity(Activity activity, int page, int num, Handler handler) {

        HttpParams params = new HttpParams();
//        params.put("userId", UserXML.getUserId(activity));
        params.put("page", String.valueOf(page));
        params.put("perPage", String.valueOf(num));

        OkHttpUtil.get(activity, URL.URL_GET_PUBLISHED_ACTIVITY, "", params, handler, MSG.MSG_GET_PUBLISHED_ACTIVITY_SUCCESS, MSG.MSG_GET_PUBLISHED_ACTIVITY_FIELD);

    }


    /**
     * 根据ID获取活动
     *
     * @param activity
     * @param page
     * @param limit
     * @param handler
     */
    public static void getActivityListById(Activity activity, String userAccId ,int page, int limit, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userAccId", userAccId);
        params.put("page", String.valueOf(page));
        params.put("limit", String.valueOf(limit));

        OkHttpUtil.post(activity, URL.URL_GET_ACTIVITY_LIST_BY_ID, "", params, handler, MSG.MSG_GET_ACTIVITY_LIST_BY_ID_SUCCESS, MSG.MSG_GET_ACTIVITY_LIST_BY_ID_FIELD);

    }

    /**
     * 我报名的活动
     *
     * @param activity
     * @param page
     * @param num
     * @param handler
     */
    public static void getApplyActivity(Activity activity, int page, int num, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("userId", UserXML.getUserId(activity));
        params.put("page", String.valueOf(page));
        params.put("num", String.valueOf(num));

        OkHttpUtil.post(activity, URL.URL_GET_APPLY_ACTIVITY, "", params, handler, MSG.MSG_GET_APPLY_ACTIVITY_SUCCESS, MSG.MSG_GET_APPLY_ACTIVITY_FIELD);

    }


    /**
     * 获取已经报名的用户
     *
     * @param activity
     * @param activityId
     * @param page
     * @param num
     * @param handler
     */
    public static void getEnlist(Activity activity, String activityId, int page, int num, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("activityId", activityId);
        params.put("page", String.valueOf(page));
        params.put("num", String.valueOf(num));

        OkHttpUtil.post(activity, URL.URL_GET_ENLIST, "", params, handler, MSG.MSG_GET_ENLIST_SUCCESS, MSG.MSG_GET_ENLIST_FIELD);

    }


    /**
     * 取消活动
     *
     * @param activity
     * @param activityId
     * @param handler
     */
    public static void cancelActivity(Activity activity, String activityId, Handler handler) {

       HttpParams params = new HttpParams();
//        params.put("activityId", activityId);
//        params.put("reason", "");
//        params.put("userId", UserXML.getUserId(activity));

        OkHttpUtil.post(activity, URL.URL_CANCEL_ACTIVITY+activityId, "", params, handler, MSG.MSG_CANCEL_ACTIVITY_SUCCESS, MSG.MSG_CANCEL_ACTIVITY_FIELD);

    }

    /**
     * 取消报名
     *
     * @param activity
     * @param activStatisId 活动报名id 非活动id
     * @param handler
     */
    public static void cancelASignUp(Activity activity, String activStatisId, Handler handler) {

        HttpParams params = new HttpParams();
        params.put("id", activStatisId);

        OkHttpUtil.post(activity, URL.URL_CANCEL_SIGN_UP, "", params, handler, MSG.MSG_CANCEL_SIGN_UP_SUCCESS, MSG.MSG_CANCEL_SIGN_UP_FIELD);

    }
}
